import React, { useRef, useEffect, forwardRef } from "react";

const Child = forwardRef((props, ref) => {
  return <div ref={ref}>child子组件</div>;
});

const App = () => {
  // useRef跟类组件的createRef差不多
  const ipt = useRef();
  const child = useRef();

  useEffect(() => {
    // ipt.current.focus()
    console.log(child.current);
  }, []);

  return (
    <>
      <h2>useRef</h2>
      <input type="text" ref={ipt} />
      <Child ref={child} />
    </>
  );
};

export default App;
